<template>
  <DialogTable
    title="选择岗位"
    v-model:show="open"
    v-model="selectData"
    :api="requestApi"
    :multiple="true"
    rowKey="workStationCode"
    labelKey="workStationName"
    :columns="columns"
    :search="searchParams"
    :showPagination="true"
    @change="selectProd"
  ></DialogTable>
</template>

<script setup name="MatDialog">
// 物料选择弹窗
import { listWorkStation } from "@/api/base/workstation";
const open = defineModel("show");
// const selectData = defineModel();
const selectData = ref([]);
const requestApi = ref(listWorkStation);
const props = defineProps({
  data: {
    type: [Array, Object],
    default: () => [],
  },
});
const { data: defaultData } = toRefs(props);
const data = reactive({
  form: {},
  columns: [
    {
      label: "岗位编号",
      align: "center",
      prop: "workStationCode",
    },
    {
      label: "岗位名称",
      align: "center",
      prop: "workStationName",
    },
    {
      label: "岗位描述",
      align: "center",
      prop: "workStationDesc",
    },
  ],
  searchParams: [
    {
      label: "岗位名称",
      prop: "workStationName",
    },
  ],
});
const dataCallback = (res) => {
  return res.rows || [];
};
const { columns, searchParams } = toRefs(data);

const emit = defineEmits(["change"]);
watch(open, (newValue) => {
  if (newValue) {
    selectData.value = defaultData.value;
  }
});
function selectProd() {
  emit("change", selectData.value);
}
</script>

<style lang="scss" scoped></style>
